package com.yupi.referral.model.vo;

import cn.hutool.json.JSONUtil;
import com.yupi.referral.model.entity.Referral;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 内推封装类
 * @TableName referral
 */
@Data
public class ReferralVO implements Serializable {
    /**
     * id
     */
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 内容
     */
    private String content;

    /**
     * 标签列表
     */
    private List<String> tags;

    /**
     * 创建用户 id
     */
    private Integer userId;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;



    /**
     * 0未审核，1通过，2未通过
     */
    private Integer state;


    private String connect;
//    /**
//     * 创建内推人信息
//     */
//    @Getter
//    private UserVO userVO;


    /**
     * 包装类转对象
     *
     * @param referralVO
     * @return
     */
    public static Referral voToObj(ReferralVO referralVO) {
        if (referralVO == null) {
            return null;
        }
        Referral referral = new Referral();
        BeanUtils.copyProperties(referralVO, referral);
        List<String> tagList = referralVO.getTags();

        if(tagList != null){
            referral.setTags(JSONUtil.toJsonStr(tagList));
        }
        return referral;
    }

    /**
     * 对象转包装类
     *
     * @param referral
     * @return
     */
    public static ReferralVO objToVo(Referral referral) {
        if (referral == null) {
            return null;
        }
        ReferralVO referralVO = new ReferralVO();
        BeanUtils.copyProperties(referral, referralVO);
//        referralVO.setTags(JSONUtil.toList(referral.getTags(), String.class));
        List<String> tagList =JSONUtil.toList(referral.getTags(), String.class);
        referralVO.setTags(tagList);
        return referralVO;
    }

    private static final long serialVersionUID = 1L;

}